package com.zhijian.medical.aop;

import com.zhijian.medical.config.Constants;
import com.zhijian.medical.service.CacheService;
import com.zhijian.medical.service.MeetingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author HCG
 * @version 1.0
 * @date 2022/6/1
 */
@Aspect
@Slf4j
@Component
public class ValidateMeetingKeyCodeAop {

    @Autowired
    private CacheService cacheService;

    @Autowired
    private MeetingService meetingService;

    @Pointcut("@annotation(com.zhijian.medical.annotation.ValidateMeetingKeyCode)")
    public void validateCustomMiniProgramTokenAop() {

    }

    @Before("validateCustomMiniProgramTokenAop()")
    public void doBefore() throws Throwable {
        String value = cacheService.get(Constants.Redis.MEETING_KEY_CODE);
        if (StringUtils.isBlank(value)) {
            //如果token已经过期，就重新来一遍
            meetingService.storeKeyCode();
        }
    }
}
